﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;

namespace Module.FlowChart.RunAble.View
{
    public partial class Form_SaveAs : Form
    {
        Dictionary<string, Action<float>> Selects;
        public Form_SaveAs()
        {
            InitializeComponent();
        }
        void Init(Dictionary<string, Action<float>> selection)
        {
            Selects = selection;
            comboBox1.Items.Clear();
            comboBox1.Items.AddRange(selection.Keys.ToArray());
            textBox1.Text = "100";
        }
        private void button1_Click(object sender, EventArgs e)
        {
            if (comboBox1.SelectedIndex < 0)
            {
                MessageBox.Show("请选择正确的类型", "错误");
                return;
            }
            float val;
            if (float.TryParse(textBox1.Text, out val))
            {
                if (val <= 0 || val >= 1000)
                {
                    MessageBox.Show("请选择正确的缩放范围(0,1000)", "错误");
                    return;
                }
                val /= 100;
            }
            else
            {
                MessageBox.Show("请选择正确的缩放范围(0,1000)", "错误");
                return;
            }
            string sel = comboBox1.Items[comboBox1.SelectedIndex] as string;
            Selects[sel].Invoke(val);
        }
        static Form_SaveAs Instance;
        static public void ShowDialog(Dictionary<string, Action<float>> selection)
        {
            if (Instance == null)
            {
                Instance = new Form_SaveAs();
            }
            Instance.Init(selection);
            Instance.ShowDialog();
        }
    }
}
